<!DOCTYPE html>
<html>
<head>
    <title>全局系统参数配置</title>
    {include file="common/inc_meta" /}
</head>
<body>
 <div id="wrapper">
    {include file="common/inc_menu" /}
       <div id="page-wrapper" class="gray-bg">
          {include file="common/inc_top" /}
            <div class="row wrapper border-bottom white-bg page-heading" style="padding-top:20px;font-weight: normal; position:relative;">
                <div class="col-sm-4">
                    <h2 style="margin-bottom:10px;">全局系统参数配置</h2>
                    <ol class="breadcrumb">
                        <li><a href="{:url('admin/system/index')}">主页</a></li>
                        <li>系统</li>
                        <li class="active"><strong>参数配置</strong></li>
                    </ol>
                </div>
                <div class="col-lg-2" style="position:absolute;right:20px;top:32px; text-align: right;">
                  <button data-toggle="button" class="btn btn-primary btn-outline" type="button" id="topaddBtn">添加参数</button>
                </div>
            </div>
            <div class="wrapper wrapper-content animated fadeInRight">

                           <!--添加参数 Begin-->
                            <div class="row" id="addConfigBox" style="display: none;">
                                <div class="col-lg-12  white-bg">
                                         <table class="table table-striped table-bordered table-hover" style="margin-bottom:0px;margin-top:10px;">
                                            <thead>
                                                <tr>
                                                  <th style="width:10%;">参数分组</th>
                                                  <th style="width:15%;">变量标题</th>
                                                  <th style="width:15%;">变量描述</th>
                                                  <th style="width:15%;">变量名</th>
                                                  <th style="width:15%;">变量值</th>
                                                  <th style="width:10%;">类型</th>
                                                  <th style="width:10%;">字典数据</th>
                                                  <th style="width:5%;">排序</th>
                                                  <th style="width:5%;text-align:center;">操作</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr>
                                                  <td style="width:10%;">
                                                       <select class="form-control" id="av_group">
                                                          <!--{volist name="cfgarr" id="mgroup"}-->
                                                           <option value="{$mgroup.group}" {if $mgroup.group eq 'custom'}selected="true"{/if}>{$mgroup.title}</option>
                                                          <!--{/volist}-->
                                                          <!--{if $add_custom gt 0}-->
                                                           <option value="custom" selected="true">自定义配置</option>
                                                          <!--{/if}-->
                                                      </select>
                                                  </td>
                                                  <td style="width:15%;"><input type="text" placeholder="输入变量标题" id="av_title" class="form-control"></td>
                                                  <td style="width:15%;"><input type="text" placeholder="输入变量描述" id="av_desc" class="form-control"></td>
                                                  <td style="width:15%;"><input type="text" placeholder="输入变量名(不可重复)" id="av_name" class="form-control"></td>
                                                  <td style="width:15%;"><input type="text" placeholder="输入变量值" id="av_value" class="form-control"></td>
                                                  <td style="width:10%;">
                                                       <select class="form-control" id="av_type">
                                                        <option value="text" selected="true">Text</option>
                                                        <option value="file">File</option>
                                                        <option value="radio">Radio</option>
                                                        <option value="select">Select</option>
                                                        <option value="textarea">Textarea</option>
                                                      </select>
                                                  </td>
                                                  <td style="width:10%;"><input type="text" placeholder="如开启|1#关闭|0" id="av_content" class="form-control"></td>
                                                  <td style="width:5%;"><input type="text" placeholder="值越小越靠" id="av_sort" class="form-control" value="0"></td>
                                                  <td style="width:5%;text-align:center;">
                                                    <button type="button" class="btn btn-outline btn-success btn-sm" onclick="addAction();"><i class="fa fa-check"></i> 添加</button>
                                                  </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                </div>
                            </div>
                           <!--添加参数 End-->

                            <div class="row">
                                <div class="col-lg-12  white-bg">

                                        <div class="layui-tab">
                                          <ul class="layui-tab-title">
                                            <!--{volist name="cfgarr" id="vo"}-->
                                               <!--{if $vo.list}-->
                                                <li {if $key eq '0'}class="layui-this"{/if} data-ligroup="{$vo.group}">{$vo.title}</li>
                                               <!--{/if}-->
                                            <!--{/volist}-->
                                          </ul>
                                          <div class="layui-tab-content">
                                            <!--{volist name="cfgarr" id="vo"}-->
                                               <!--{if $vo.list}-->
                                                <div class="layui-tab-item {if $key eq '0'}layui-show{/if}">
                                                    {include file="common/inc_config" /}
                                                </div>
                                               <!--{/if}-->
                                            <!--{/volist}-->
                                          </div>
                                        </div>

                                </div>
                            </div>

            </div>
     {include file="common/inc_footer" /}
     </div>
 </div>
<!-- Mainly scripts -->
{include file="common/inc_jsfile" /}

<!-- iCheck -->
<script src="__ADMIN__/js/plugins/iCheck/icheck.min.js"></script>
<script src="__STATIC__/ajaxfileupload.js?v={$site.version}"></script>
<script>
$(function(){
    $('.i-checks').iCheck({
        checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-green',
    });
    $('#topaddBtn').click(function(){
        let _obj = $('#addConfigBox');
        if(_obj.is(':hidden'))
        {
        　 _obj.fadeIn(500);
           $('#av_title').focus();
        }else{
        　 _obj.fadeOut(200);
           $('#av_group').val('custom');
           $('#av_title').val('');
           $('#av_desc').val('');
           $('#av_name').val('');
           $('#av_value').val('');
           $('#av_content').val('');
           $('#av_sort').val('0');
        }
    });
    //上传绑定事件
    $('.layui-tab-content').find('input:file').on('change',function(b){
       if($(this).val() != '')
       {
         AjaxUploadFile({savedir:'system',inputname:$(this).attr('name'),imgid:$(this).attr('id'),iptobj:$(this).data('iptobj'),imgobj:$(this).data('imgobj')});
       }
    });
});
//上传动作
function AjaxUploadFile(param)
{
  layer.msg('上传中，请稍候...', {icon: 16,time:50000,shade:[0.4,'#000000']});
  $.ajaxFileUpload({
      url: "{:url('admin/index/uploadpic')}", //用于文件上传的服务器端请求地址
      secureuri: false, //是否需要安全协议，一般设置为false
      fileElementId: param.imgid, //文件上传域的ID
      data:param, //要上传参数
      dataType:"json", //返回值类型 一般设置为json
      success: function(data)  //服务器成功响应处理函数
      {
        layer.closeAll();
        $("#" + param.iptobj).val(data.img_path);
        $("#" + param.imgobj).empty();
        $("#" + param.imgobj).append('<img src="' + data.img_url + '" style="width:50px;height:auto;"/>');
      },
      error: function (data, status, e)//服务器响应失败处理函数
      {
        layer.closeAll();
        layer.msg('上传出错：' + e, {time: 2000,anim: 6,shade:[0.4,'#000000']});
        return false;
      }
  });
}
//新增配置参数
function addAction()
{
  var _param = {};
  _param.av_group = $.trim($('#av_group').val());
  _param.av_title = $.trim($('#av_title').val());
  _param.av_desc = $.trim($('#av_desc').val());
  _param.av_name = $.trim($('#av_name').val());
  _param.av_value = $.trim($('#av_value').val());
  _param.av_type = $.trim($('#av_type').val());
  _param.av_content = $.trim($('#av_content').val());
  _param.av_sort = $.trim($('#av_sort').val());
  if(_param.av_group.length <= 0)
  {
     layer.msg('请输入参数分组英文字母', {time: 2000,anim: 6,shade:[0.4,'#000000']});
     return false;
  }
  if(_param.av_title.length <= 0)
  {
     layer.msg('请输入变量标题', {time: 2000,anim: 6,shade:[0.4,'#000000']});
     return false;
  }
  if(_param.av_name.length <= 0)
  {
     layer.msg('请输入不可重复的变量名', {time: 2000,anim: 6,shade:[0.4,'#000000']});
     return false;
  }
  _Admin.ajax("{:url('admin/system/add')}",_param,function(d){
   if(d.err == '0')
   {
     layer.msg(d.msg, {time: 1500,shade:[0.4,'#000000']},function(){
        $('#av_name').val('');  
        $('#av_value').val(''); 
        $('#av_title').val('');
        $('#av_title').focus();
     });
   }else{
     layer.msg(d.msg, {time: 2000,anim: 6,shade:[0.4,'#000000']});
   }
  });
}

//保存
function saveAction(_obj)
{
  var _FormBox = $('#' + _obj),_dataArr = {}, _k = 0, _keyArr = [];
  _FormBox.find('select').each(function(i,v){
      var _name = $.trim($(this).attr('name'));
      if(typeof(_name) != "undefined" &&  $.inArray(_name,_keyArr) <= 0 && _name.length > 0)
      {
          _dataArr[_k] = {};
          _dataArr[_k]['id'] = $.trim($(this).data('sqlid'));
          _dataArr[_k]['name'] = _name;
          _dataArr[_k]['value'] = $.trim($(this).val());
          _dataArr[_k]['sort'] = $.trim($('#' + _name + '_sort').val());
          _keyArr[_k] = _name;
          _k++;
      }
  });
  _FormBox.find('input:text').each(function(i,v){
      var _name = $.trim($(this).attr('name'));
      if(typeof(_name) != "undefined" &&  $.inArray(_name,_keyArr) <= 0 && _name.length > 0)
      {
          _dataArr[_k] = {};
          _dataArr[_k]['id'] = $.trim($(this).data('sqlid'));
          _dataArr[_k]['name'] = _name;
          _dataArr[_k]['value'] = $.trim($(this).val());
          _dataArr[_k]['sort'] = $.trim($('#' + _name + '_sort').val());
          _keyArr[_k] = _name;
          _k++;
      }
  });
  _FormBox.find('input:radio').each(function(i,v){
      var _name = $.trim($(this).attr('name'));
      var _val = $("input[name='" + _name + "']:checked").val();
      if(typeof(_name) != "undefined" &&  $.inArray(_name,_keyArr) <= 0 && _name.length > 0)
      {
          _dataArr[_k] = {};
          _dataArr[_k]['id'] = $.trim($(this).data('sqlid'));
          _dataArr[_k]['name'] = _name;
          _dataArr[_k]['value'] = $.trim(_val);
          _dataArr[_k]['sort'] = $.trim($('#' + _name + '_sort').val());
          _keyArr[_k] = _name;
          _k++;
      }
  });
  _FormBox.find('textarea').each(function(i,v){
      var _name = $.trim($(this).attr('name'));
      if(typeof(_name) != "undefined" &&  $.inArray(_name,_keyArr) <= 0 && _name.length > 0)
      {
          _dataArr[_k] = {};
          _dataArr[_k]['id'] = $.trim($(this).data('sqlid'));
          _dataArr[_k]['name'] = _name;
          _dataArr[_k]['value'] = $.trim($(this).val());
          _dataArr[_k]['sort'] = $.trim($('#' + _name + '_sort').val());
          _keyArr[_k] = _name;
          _k++;
      }
  });
  _Admin.ajax("{:url('admin/system/saveconfig')}",{data:_dataArr},function(d){
   if(d.err == '0')
   {
     layer.msg(d.msg, {time: 1500,shade:[0.4,'#000000']},function(){window.location.reload();});
   }else{
     layer.msg(d.msg, {time: 2000,anim: 6,shade:[0.4,'#000000']});
   }
  });
}
</script>
</body>
</html>
